﻿// copyright (c) 2025 author:fio66<fio66@foxmail.com>. All rights reserved.
// date: 2025-08-22 10:59:19

#ifndef _AUDIO_PLAYER_SRC_PLAYER_AUDIO_PLAYER_H_
#define _AUDIO_PLAYER_SRC_PLAYER_AUDIO_PLAYER_H_

#include <memory>
#include <string_view>

#include "ffmpeg_warpper_export.h"
#include "include/cef_base.h"
#include "src/event/event_handler.h"

namespace fio66 {
class AudioPlayer : public MediaDataCallback,
                    public EventHandler,
                    public virtual CefBaseRefCounted {
 public:
  AudioPlayer(EventDispatcher* dispatcher)
      : EventHandler(dispatcher), demuxer_(CreateDemuxer()) {}

  ~AudioPlayer() = default;

  bool Play(std::string_view url);
  void Pause();
  void Stop();
  void SetVolume(int volume);
  int GetVolume();
  void Seek(double time_s);
  double GetCurrentTime();
  double GetDuration();

 private:
  void OnRecieveMediaData(MediaDataType type, uint8_t* data, size_t size) final;
  void OnEvent(EventType event_type, const std::any& data) final;

 private:
  std::unique_ptr<Demuxer> demuxer_;

  IMPLEMENT_REFCOUNTING(AudioPlayer);
};

}  // namespace fio66

#endif  // _AUDIO_PLAYER_SRC_PLAYER_AUDIO_PLAYER_H_
